﻿Imports System.Data
Imports System.Data.Odbc
Imports WSEntidades
Imports MySql.Data.MySqlClient

Public Class TiposProductosFact
    Public Shared Function Build(ByVal dr As MySqlDataReader, ByVal boolBuildFamilia As Boolean) As TiposProductos
        Dim tmpTipos As TiposProductos = New TiposProductos()
        Try
            tmpTipos = buildInternal(dr.Item("IdTipo"),
                                     dr.Item("Clave"),
                                     dr.Item("Descripcion"),
                                     dr.Item("Estatus"),
                                     dr.Item("IdFamilia"))
            If (boolBuildFamilia) Then
                tmpTipos.Familia = FamiliasFact.Build(dr)
            End If
            Return tmpTipos
        Catch ex As Exception
            Throw
        Finally
            tmpTipos = Nothing
        End Try
    End Function

    Public Shared Function buildInternal(ByVal idTipo As Object, ByVal clave As Object, ByVal descripcion As Object,
                                   ByVal estatus As Object, ByVal idFamilia As Object) As TiposProductos
        Dim tmpTipos As TiposProductos = New TiposProductos()
        Try
            With tmpTipos
                .Id = convertDTFromDb.convertInt32(idTipo)
                .Clave = convertDTFromDb.ConvertString(clave)
                .Descripcion = convertDTFromDb.ConvertString(descripcion)
                Select Case convertDTFromDb.ConvertString(estatus)
                    Case "A"
                        .Status = TiposProductos.EstatusTiposProductos.Activo
                    Case "I"
                        .Status = TiposProductos.EstatusTiposProductos.Inactivo
                    Case Else
                        .Status = TiposProductos.EstatusTiposProductos.Inactivo
                End Select
                .Familia = New FamiliasBE
                .Familia.IdFamilia = convertDTFromDb.convertInt32(idFamilia)
            End With
            Return tmpTipos
        Catch ex As Exception
            Throw
        Finally
            tmpTipos = Nothing
        End Try
    End Function
End Class
